/**
 * 
 */
package com.tju.worker;

/**
 * <p>
 * Worker executor
 * </p>
 * 
 */
public class WorkerExecutor extends Thread {

	/**
	 * <p>
	 * workers queue
	 * </p>
	 */
	private WorkerQueue workerQueue;

	private volatile boolean kill;

	public WorkerExecutor(WorkerQueue workerQueue) {
		this.workerQueue = workerQueue;
		kill = false;
	}

	public void run() {
		while (!kill) {
			if (currentThread() == this)
				yield();
			workerQueue.pollWorker().start();
		}
		workerQueue.destroy();
	}

	public void kill() {
		kill = true;
	}

}
